//
// Created by Administrator on 2025/4/22/周二.
//成员函数做友元
//
#include "iostream"

using namespace std;

class Building;

class GoodGay {
public:
    GoodGay();

    void visit();//只让visit函数作为Building的好朋友，可以访问Building中私有内容
    void visit2();

private:
    Building *building;
};


//建筑类
class Building {
//    告诉编译器 goodGay类中的visit成员函数是Building类的好朋友，可以访问私有内容
    friend void GoodGay::visit();
//公开构造方法
public:
    Building();

public:
    string SittingRoom;
private:
    string BedRoom;

};

Building::Building() {
    this->BedRoom = "卧室";
    this->SittingRoom = "客厅";
}

GoodGay::GoodGay() {
    building = new Building();
}

//因为声明了此函数和Building类是好朋友，所以可以直接访问private数据
void GoodGay::visit() {
    cout << "好基友正在访问" << building->SittingRoom << endl;
    cout << "好基友正在访问" << building->BedRoom << endl;
}
void GoodGay::visit2() {
    cout << "好基友正在访问" << building->SittingRoom << endl;
    cout << "好基友正在访问" << building->BedRoom << endl;//会报错，因为不是好朋友
}
void test01() {
    GoodGay g;
//    g.visit();
    g.visit2();
}


int main() {
    test01();
}